class CustomizeController < ApplicationController
	
	def show
		@brand = Brand.find(params[:id])
		@scheme = @brand.colors[1]
		@monogram = Monogram.find_by_color_id(@scheme.id)
		@corner = Corner.find_by_color_id(@scheme.id)	
		@design = Design.find_by_color_id_and_brand_id(@scheme.id,@brand.id)
	end
	
	def select_monogram
		@scheme = Color.find(params[:scheme])
		@brand = Brand.find(params[:brand])
		@corner_family = params[:corner_family]
		render :update do |page|
			page.replace_html :monograms, :partial => 'monograms' 
		end
	end
	
	def select_corners
		@scheme = Color.find(params[:scheme])
		@brand = Brand.find(params[:brand])
		@monogram_family = params[:monogram_family]
		render :update do |page|
			page.replace_html :corners, :partial => 'corners' 
		end
	end
	
	def change_monogram
		@monogram = Monogram.find_by_color_id_and_monogram_family_id(params[:scheme], params[:family])
		@monogram_family = @monogram.monogram_family.id
		@corner_family = params[:corner_family]
		@brand = Brand.find(params[:brand])
		
		render :update do |page|
			page.replace_html :monogram, "<img src=\"/binary/monogram/#{@monogram.id}\">" 
			page.replace_html :color_options, :partial => "color_options"
		end
	end
	
	def change_corners
		@corner = Corner.find_by_color_id_and_corner_family_id(params[:scheme], params[:family])
		@corner_family = @corner.corner_family.id
		@monogram_family = params[:monogram_family]
		@brand = Brand.find(params[:brand])
		
		render :update do |page|
			page.replace_html :corner_top, link_to_remote(image_tag("/binary/corner/#{@corner.id}"), :url => { :action => 'select_corners', :scheme => params[:scheme], :brand => @brand.id, :monogram_family => params[:monogram_family]})
			page.replace_html :corner_bottom, link_to_remote(image_tag("/binary/corner_bottom/#{@corner.id}"), :url => { :action => 'select_corners', :scheme => params[:scheme], :brand => @brand.id,  :monogram_family => params[:monogram_family]})
			page.replace_html :color_options, :partial => "color_options"
		end
	end	
	
	def change_color
		@monogram = Monogram.find_by_color_id_and_monogram_family_id(params[:id], params[:monogram_family])
		@corner = Corner.find_by_color_id_and_corner_family_id(params[:id], params[:corner_family])
		@corner_family = params[:corner_family]
		@scheme = Color.find(params[:id])
		@brand = Brand.find(params[:brand])
		@design = Design.find_by_color_id_and_brand_id(@scheme.id,@brand.id)
		render :update do |page|
			page.replace_html :monogram, link_to_remote(image_tag("/binary/monogram/#{@monogram.id}"), :url => { :action => 'select_monogram', :scheme => params[:id]}) 
			page.replace_html :monograms, :partial => "monograms"
			page.replace_html :corner_top, link_to_remote(image_tag("/binary/corner/#{@corner.id}"), :url => { :action => 'select_corners', :scheme => @scheme.id, :brand => @brand.id, :monogram_family => params[:monogram_family]})
			page.replace_html :corner_bottom, link_to_remote(image_tag("/binary/corner_bottom/#{@corner.id}"), :url => { :action => 'select_corners', :scheme => @scheme.id, :brand => @brand.id,  :monogram_family => params[:monogram_family]})
			page.replace_html :design, "<img src=\"/binary/design/#{@design.id}\">"
		end
	end
end
